package com.wymobilearchitecture.demo.tab

import android.os.Bundle
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.wy.w_ui.tab.common.IWTabLayout
import com.wy.w_ui.tab.top.WTabTop
import com.wy.w_ui.tab.top.WTabTopInfo
import com.wy.w_ui.tab.top.WTabTopLayout
import com.wymobilearchitecture.R

class TabTopActivity : AppCompatActivity() {

    private val topData: List<String> =
        listOf("运动", "装修", "家具", "百货", "汽车", "家电", "零食", "鞋子", "数码", "服装", "成人")

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_tab_top)

        initTabTop()
    }

    private fun initTabTop() {

        val tabTop: WTabTopLayout = findViewById(R.id.tab_top)

        val tabList: MutableList<WTabTopInfo<*>> = ArrayList()

        val defColor: Int = resources.getColor(R.color.tabTopDefaultColor)
        val tintColor: Int = resources.getColor(R.color.tabTopTintColor)

        for (topDatum in topData) {
            tabList.add(WTabTopInfo(topDatum, defColor, tintColor))
        }

        tabTop.inflateInfo(tabList)

        tabTop.addTabSelectChangeListener { _, _, nextInfo ->

            Toast.makeText(this@TabTopActivity,nextInfo.name,Toast.LENGTH_SHORT).show()
        }

        tabTop.defaultSelected(tabList[0])
    }

}